package com.objectcarpentry.kaylee.gstreamer.internal;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;
import org.gstreamer.TagList;

import com.objectcarpentry.kaylee.Track;

public class Utilities {

	
	public static void storeMetadata(Track t, TagList l){
		for (String tagName : l.getTagNames()) {
			EStructuralFeature feature = t.eClass().getEStructuralFeature(tagName);
			if (feature != null && feature.getEType() == EcorePackage.Literals.ESTRING){
				if (feature.getUpperBound() == EStructuralFeature.UNBOUNDED_MULTIPLICITY ){
					EList<String> list = (EList<String>) t.eGet(feature);
					for (Object tagData : l.getValues(tagName)) {
						list.add(tagData.toString());
					}
				}
				else {
					t.eSet(feature, l.getValue(tagName, 0).toString());
				}
			}
		}
	}

	
	
	
}
